package com.houger.ddd.seckill.infra.datamanager;

import com.houger.ddd.datamanager.manager.aop.DataCache;
import com.houger.ddd.datamanager.manager.aop.DataCacheEvict;
import com.houger.ddd.datamanager.utils.CacheType;
import com.houger.ddd.seckill.infra.entity.ActivityTemplateBasic;
import com.houger.ddd.seckill.repository.ActivityTemplateBasicRepository;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;


@Service
public class ActivityTemplateBasicDataManager {

    @Resource
    ActivityTemplateBasicRepository activityTemplateBasicRepository;

    @DataCache(group = "activity-basic",key = "('id=').concat(#id)",type = {CacheType.LOCAL, CacheType.REDIS},localExpire = 1 * 60, redisExpire = 1 * 60)
    public ActivityTemplateBasic queryBasicById(Long id){
        return this.activityTemplateBasicRepository.findById(id).orElseThrow();
    }

    @DataCache(group = "activity-basic",key = "('code=').concat(#templateCode)",type = {CacheType.LOCAL, CacheType.REDIS},localExpire = 1 * 60, redisExpire = 1 * 60)
    public ActivityTemplateBasic queryBasicByCode(String templateCode){
        return this.activityTemplateBasicRepository.findByTemplateCode(templateCode);
    }

    @DataCacheEvict(group = "activity-basic",key = {
            "('id=').concat(#id)",
            "('code=').concat(#templateCode)"},
            type = {CacheType.LOCAL, CacheType.REDIS}
    )
    public void evict(Long id, String templateCode){

    }


}
